package com.tencent.sr.iris.basic.mp.restapi.controller;

import com.tencent.sr.iris.basic.mp.interfaces.request.ConvertShortUrlRequest;
import com.tencent.sr.iris.basic.mp.interfaces.response.ConvertShortUrlResponse;
import com.tencent.sr.iris.basic.mp.service.ShortUrlService;
import com.tencent.sr.rmall.common.primitive.HttpResult;
import com.tencent.sr.rmall.springbootstarter.utils.JsonUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Copyright (C) 2021 Limited, a Tencent company. All rights reserved.
 *
 * @author acewang@tencent.com
 * @date 2021/12/19 10:57 下午
 */
@RestController
@Slf4j
@Api("cos相关接口")
@RequestMapping("/iris/basic/mp/v1/shorturl")
public class ShortUrlController {

    @Autowired(required = false)
    private ShortUrlService shortUrlService;

    @PostMapping("/convert")
    @ApiOperation("转换短链")
    public HttpResult<ConvertShortUrlResponse> convertShortUrl(@RequestBody @Validated ConvertShortUrlRequest request) {
        log.info("convertShortUrl request {}", JsonUtils.toJsonString(request));
        return HttpResult.succ(shortUrlService.convertShortUrl(request));
    }

}
